/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.niedziela12.pai.ejb.dto;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;
import com.niedziela12.pai.ejb.entities.Room;

/**
 *
 * @author Kamil
 */
@XmlType(propOrder = {
    "id"
})
@XmlAccessorType(XmlAccessType.FIELD)
public class RoomDTO implements Serializable {
    @XmlTransient
    private static final long serialVersionUID = 1L;
    @XmlElement(name = "ROOM_ID")
    private Long id;
    @XmlTransient
    private HotelDTO hotel;
    @XmlTransient
    private int capacity;
    @XmlTransient
    private double price;
    
    public RoomDTO(){        
    }

    public RoomDTO(Room room) {
        if (room != null) {
            this.id = room.getId();
            this.hotel = new HotelDTO(room.getHotel());
            this.capacity = room.getCapacity();
            this.price = room.getPrice();
        }
    }
    
    public Room toRoom(){
        Room r = new Room();
        r.setCapacity(capacity);
        r.setHotel(hotel.toHotel());
        r.setId(id);
        r.setPrice(price);
        return r;
    }
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public HotelDTO getHotel() {
        return hotel;
    }

    public void setHotel(HotelDTO hotel) {
        this.hotel = hotel;
    }

    public int getCapacity() {
        return capacity;
    }

    public void setCapacity(int capacity) {
        this.capacity = capacity;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof RoomDTO)) {
            return false;
        }
        RoomDTO other = (RoomDTO) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Room "+ id + " in hotel '" + hotel.getName() + "'" ;
    }

}
